package cn.iocoder.yudao.module.handguard.service.userbasetable9;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable9.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable9.UserBaseTable9DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable9.UserBaseTable9Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable9.UserBaseTable9Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 商业商住楼写字楼二次抵押 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable9ServiceImpl implements UserBaseTable9Service {

    @Resource
    private UserBaseTable9Mapper userBaseTable9Mapper;

    @Override
    public Long createUserBaseTable9(UserBaseTable9CreateReqVO createReqVO) {
        // 插入
        UserBaseTable9DO userBaseTable9 = UserBaseTable9Convert.INSTANCE.convert(createReqVO);
        userBaseTable9Mapper.insert(userBaseTable9);
        // 返回
        return userBaseTable9.getId();
    }

    @Override
    public void updateUserBaseTable9(UserBaseTable9UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable9Exists(updateReqVO.getId());
        // 更新
        UserBaseTable9DO updateObj = UserBaseTable9Convert.INSTANCE.convert(updateReqVO);
        userBaseTable9Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable9(Long id) {
        // 校验存在
        validateUserBaseTable9Exists(id);
        // 删除
        userBaseTable9Mapper.deleteById(id);
    }

    private void validateUserBaseTable9Exists(Long id) {
        if (userBaseTable9Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE9_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable9DO getUserBaseTable9(Long id) {
        LambdaQueryWrapper<UserBaseTable9DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable9DO::getId,id);
        return userBaseTable9Mapper.selectOne(queryWrapper);
    }

    @Override
    public List<UserBaseTable9DO> getUserBaseTable9List(Long id) {
        LambdaQueryWrapper<UserBaseTable9DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable9DO::getApplicationId,id);
        return userBaseTable9Mapper.selectList(queryWrapper);
    }

    @Override
    public PageResult<UserBaseTable9DO> getUserBaseTable9Page(UserBaseTable9PageReqVO pageReqVO) {
        return userBaseTable9Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable9DO> getUserBaseTable9List(UserBaseTable9ExportReqVO exportReqVO) {
        return userBaseTable9Mapper.selectList(exportReqVO);
    }

}
